<?php
// Desired folder structure
//$structure = 'path/depth1/depth2/depth3/';
//
//// To create the nested structure, the $recursive parameter 
//// to mkdir() must be specified.
//
//if (!mkdir($structure, 0, true)) {
//    die('Failed to create folders...');
//}
//
//
//if ($handle = opendir('/path/to/files')) {
//    echo "Directory handle: $handle\n";
//    echo "Entries:\n";
//
//    /* This is the correct way to loop over the directory. */
//    while (false !== ($entry = readdir($handle))) {
//        echo "$entry\n";
//    }
//
//    /* This is the WRONG way to loop over the directory. */
//    while ($entry = readdir($handle)) {
//        echo "$entry\n";
//    }
//
//    closedir($handle);
//}
// ...

if ($handle = opendir('./path')) {
    while (false !== ($entry = readdir($handle))) {
        if ($entry != "." && $entry != "..") {
            echo "$entry\n";
        }
    }
    closedir($handle);
}
?>